import {createRouter, createWebHashHistory, createWebHistory} from "vue-router";
// import {useKeepaliveStore} from "@/stores/modules/keepaliveStore.js";
import {routesIndexObj, whiteRoutes} from "@/router/config.js";
import routes from "@/router/config.js";

const router = createRouter({
    history: createWebHistory(),
    routes,
});

router.beforeEach((to, from) => {
    const env = import.meta.env;
    document.title = to.meta.title + " - " + env.VITE_APP_TITLE;
    // const keepaliveStore = useKeepaliveStore();
    // keepaliveStore.addKeepAlive(to);
    // if (to.name === "login") {
    //   to.query.redirect = (from && from.fullPath) || "/";
    // }
});

// router.afterEach((to, from) => {
//     // const fromIndex = routesIndexObj[from.name] || 0;
//     // const toIndex = routesIndexObj[to.name];
//     if (!whiteRoutes.includes(from.name)) {
//         const keepaliveStore = useKeepaliveStore();
//         keepaliveStore.removeKeepAlive(from);
//     }
//     return true;
// });

export default router;
